<?php
switch ($_GET['req']) {
	//订单信息页
	case 'orderinfo':
		//没有订单编号
		if( !isset($_GET['id'])){
		    echo 'error';exit;
		}
              
               $_POST['id']=$_GET['id'];//配送单号
                //配送订单信息
               $modelClass = 'app\com\simtoon\publicmodels\Acceptance';
               $data=YiiComm::executeByMethod($modelClass,'selectInfor',$_POST);
               $infor=$data->getModels();
               $baseinfor=$infor[0];
               //0待配送，1运输中，2待安装，3待验收，4订单完成，5异常单，6维修单,7配送单还未进行确认
               if($baseinfor['orderstatus'] < 2){
               	   $status=1;//运输中
               }elseif($baseinfor['orderstatus'] == 4){
                       $status=3;//订单完成
               }else{
                      $status=2;//安装中
               }
               $baseinfor['time']=substr($baseinfor['time'],0,16);
               //配送类型  1配送安装单，2安装单，3为配送单
               if($baseinfor['style'] == 1){
                     $baseinfor['style']='货物送装';
               }elseif($baseinfor['style'] == 2){
                     $baseinfor['style']='货物安装';
               }else{
                     $baseinfor['style']='货物配送';
               }
             //查询客户是否已经验收评价
              $data=YiiComm::executeByMethod($modelClass,'selectLcuk',$_POST);
		$res=$data->getModels();
		$res=$res[0];
		if(empty($res['disnum'])){//未验收评价
		   $yp=0;
		}else{//已验收评价
		   $yp=1;
		}
               //货品信息
               $data=YiiComm::executeByMethod($modelClass,'selectGood',$_POST);
               $infor=$data->getModels();  
               
		include template('public/tpl/acceptance/goods_message.html',1);
		break;
	//服务评价页
	case 'evaluate':
		//没有订单编号
		if( !isset($_GET['id'])){
		    echo 'error';exit;
		}
              
               $_POST['id']=$_GET['id'];//配送单号
                //配送订单信息
               $modelClass = 'app\com\simtoon\publicmodels\Acceptance';
               $data=YiiComm::executeByMethod($modelClass,'selectInfor',$_POST);
               $infor=$data->getModels();
               $baseinfor=$infor[0];
               $baseinfor['time']=substr($baseinfor['time'],0,16);
		include template('public/tpl/acceptance/goods_sevice.html',1);
		break;
	//提交成功页
	case 'result':
		if( !isset($_GET['id'])){
		    echo 'error';exit;
		}
		$id=$_GET['id'];
		include template('public/tpl/acceptance/submit_success.html',1);
		break;
	//抽奖页面
	case 'luckdraw':
		if( !isset($_GET['id'])){
		    echo 'error';exit;
		}
		$_POST['id']=$_GET['id'];
		$modelClass = 'app\com\simtoon\publicmodels\Acceptance';
		$data=YiiComm::executeByMethod($modelClass,'selectLcuk',$_POST);
		$infor=$data->getModels();
		$res=$infor[0];
		if(empty($res['luck'])){
		    echo 'errora';exit;
		}
		$id=$_GET['id'];
		include template('public/tpl/acceptance/reward_return.html',1);
		break;
	//保存提交信息
	case 'save':
		
		$_POST['id']=$_POST['number'];
		  //是否已经提交过
              $modelClass = 'app\com\simtoon\publicmodels\Acceptance';
              $data=YiiComm::executeByMethod($modelClass,'selectLcuk',$_POST);
		$infor=$data->getModels();
		$res=$infor[0];
		if(!empty($res['disnum'])){
		    die(json_encode(array('result'=>'fail','msg'=>'您已经评价过本次服务了')));
		    exit;
		}
		//保存提交的评价
               $data=YiiComm::executeByMethod($modelClass,'saveEvaluate',$_POST);
               if($data['result'] == 'success'){
               	 $url=S_URL."/device/SendInstall/storedisinfo";
               	 $res=postUrl($url,array('distributionline'=>$_POST['number']));//计算本次的费用
                }
               die(json_encode($data));
		break;
	//抽奖
	case 'luck':
		$res=json_encode(luck($_POST['id']));
		die($res);
		break;
	default:
		# code...
		break;
}
//用户抽奖
function luck($post){
//	$post['id']=$id;
	//是否已经抽过奖
	$modelClass = 'app\com\simtoon\publicmodels\Acceptance';
	$data=YiiComm::executeByMethod($modelClass,'selectLcuk',$_POST);
	$infor=$data->getModels();
	$res=$infor[0];
	//已经抽过奖
	if(!empty($res['luck'])){
	   return array('result'=>'success');
	  //抽奖
	}else{
	     $data=YiiComm::executeByMethod($modelClass,'luckDraw',$_POST);
	     return $data;
	}
}
//post方式访问接口
function postUrl($url,$data){
	$ch = curl_init();
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch,CURLOPT_POST,1);
	curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
	$output = curl_exec($ch);
	curl_close($ch);
	return $output;
}

?>